import { useState } from 'react'
import {Navigate, useLocation,Route, Routes} from 'react-router-dom';
import routerList from './router/index'
import './App.css'

const App=()=>{
  
  const location=useLocation();
  const renderRouter=(list:any)=>{
    return list.map((item:any)=>{
      return(
        <Route path={item.path} key={item.path}
         element={
          location.pathname== "/"?(
            <Navigate to="/home/index"></Navigate>
          ):(
            <item.element></item.element>
          )
         }
        >
          {item.children && renderRouter(item.children)}
        </Route>
      )
    })
  };
  return (
    <div>
      <Routes>{renderRouter(routerList)}</Routes>
    </div>
  )
}

export default App
